package com.yun.datastructure.linear.stack.leetcode;

import java.util.LinkedList;

public class Leetcode150 {

    public int evalRPN(String[] tokens){
        LinkedList<Integer> stack=new LinkedList<>();
        for (String t : tokens) {
            switch (t){
                case "+"->{
                    Integer b = stack.pop();
                    Integer a = stack.pop();
                    stack.push(a+b);
                }
                case "-"->{
                    Integer b = stack.pop();
                    Integer a = stack.pop();
                    stack.push(a-b);
                }
                case "*"->{
                    Integer b = stack.pop();
                    Integer a = stack.pop();
                    stack.push(a*b);
                }
                case "/"->{
                    Integer b = stack.pop();
                    Integer a = stack.pop();
                    stack.push(a/b);
                }
                default -> {
                    stack.push(Integer.parseInt(t));
                }
            }
        }
        return stack.pop();
    }
}
